package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.export.naming.IdentityNamingStrategy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//@RestController //1.返回数据是JSON数据2.表示Ajax请求的结束3.返回值的是字符串本身
                //4.不会执行SpringMVC中的组件 视图解析器
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    /**
     *
     */
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Integer> ids=new ArrayList<>();
        ids.add(1);
        ids.add(2);
        ids.add(3);
        List<User> userList=userService.findAll();
        model.addAttribute("userList",userList);
        model.addAttribute("msg","你好SpringBoot");
        model.addAttribute("ids",ids);
        return "userList";
    }
    @RequestMapping("/toAjax")
    public String toAjax(){
        return "ajax";
    }
    @RequestMapping("/ajaxUser")
    public List<User> ajaxUser(Integer id,String name){
        System.out.println("id参数:"+id);
        System.out.println("name参数:"+name);
        return userService.findAll();
    }

}
